<?php
namespace app\admin\controller;
use app\admin\model\IndexTableModel;
use app\admin\model\JoinTableModel;
use think\Db;
use think\Request;
use app\common\model\User;
use app\common\model\UserLevel;
use app\common\validate\UserValidate;

require_once (__DIR__.'/../../../vendor/ReidsLock.class.php');
class FaextendController extends Controller
{

    /**
     * 快手推广
     * User:@hang
     */
    public function ksindex(Request $request)
    {
        $param = $request->param();
        $whehe = array();
        if (isset($param['member_id']) && !empty($param['member_id'])) {
            $whehe[] = ['b.member_id','=',$param['member_id']];
        }
        if (isset($param['s_member_id']) && !empty($param['s_member_id'])) {
            $whehe[] = ['b.me_parent','=',$param['s_member_id']];
        }
        $whehetime = '';
        if (isset($param['me_add_time']) && !empty($param['me_add_time'])) {
            $time_arr = explode(' - ', $param['me_add_time']);
            $start_time = strtotime($time_arr[0]);
            $end_time = strtotime($time_arr[1]);
            $whehetime = "b.me_add_time >= $start_time AND b.me_add_time <= $end_time";
        }
        if (isset($param['me_zhuxiao']) && $param['me_zhuxiao'] != '') {
            $whehe[] = ['b.me_zhuxiao','=',$param['me_zhuxiao']];
        }
        if (isset($param['me_sex']) && $param['me_sex'] != '') {
            $whehe[] = ['b.me_sex','=',$param['me_sex']];
        }
        if (isset($param['me_zx']) && $param['me_zx'] != '') {
            $whehe[] = ['b.me_zx','=',$param['me_zx']];
        }
        if (isset($param['me_is_vip']) && $param['me_is_vip'] != '') {
            $whehe[] = ['b.me_is_vip','=',$param['me_is_vip']];
        }
        if (isset($param['all_num']) && $param['all_num'] != '') {
            $whehe[] = ['c.all_num','>=',$param['all_num']];
        }
        $order = 'b.me_add_time desc';
        if (isset($param['px']) && $param['px'] != '') {
            switch($param['px']){
                case '1': $order = 'cz_money desc';break;
                case '2': $order = 'wrj_time desc';break;
                case '3': $order = 'c.all_num desc';break;
            }
        }

        $whehetimecz = '';
        $grwhehetimecz = '';
        if (isset($param['cz_add_time']) && !empty($param['cz_add_time'])) {
            $time_arr = explode(' - ', $param['cz_add_time']);
            $start_time = strtotime($time_arr[0]);
            $end_time = strtotime($time_arr[1]);
            $whehetimecz = "add_time >= $start_time AND add_time <= $end_time";
            $grwhehetimecz = " and cz.add_time >= $start_time and cz.add_time <= $end_time";
        }

        $whehe[] = ['a.member_id','neq',0];
        $IndexTableModel = New IndexTableModel();
        $data = Db::table('z_tuiguang_monitoring_ks')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where($whehe)
            ->where($whehetime)
            ->field('a.id as tg_id,a.type as tg_type,a.accountid as tg_accountid,a.aid as tg_aid,a.member_id,b.me_uid,b.me_phone,b.me_add_time,b.me_nick_name,b.me_img,b.me_parent,b.me_bind_type,b.me_bind_time,b.me_sex,b.me_zx,b.me_xn_zx,b.me_status,b.me_zhuxiao,b.me_is_real,b.me_realname,b.me_is_vip,b.me_area_code,b.me_is_circle,b.me_carname,b.me_circle_id,b.me_car_type,c.w_id,c.w_num,c.all_num,c.s_list,(select sum(wrj.stay_num) from fa_stay_software wrj where a.member_id = wrj.member_id) as wrj_time,(select sum(ssp.stay_num) from fa_stay_video ssp where a.member_id = ssp.member_id) as ssp_time,(select sum(cz.pay_money) from fa_recharge_stamp_order cz where a.member_id = cz.member_id'.$grwhehetimecz.') as cz_money,(select count(cz.id) from fa_recharge_stamp_order cz where a.member_id = cz.member_id'.$grwhehetimecz.') as cz_num')
            ->order($order)
            ->paginate($this->admin['per_page'],false,['query'=>request()->param()]);

        $adminid = $this->uid;
        $data->each(function ($v, $k)use($IndexTableModel,$adminid) {
            $v['tr_color'] = 0;
            if(!empty($v['cz_money'])){
                $v['tr_color'] = 1;//充值显示绿色行
            }
            if($v['wrj_time'] < $v['ssp_time']){
                $v['wrj_time'] = $v['ssp_time'];
            }
            $v['wrj_time'] = secondChanage($v['wrj_time']);
            $v['ssp_time'] = secondChanage($v['ssp_time']);
            $v['cz_money'] = !empty($v['cz_money'])?$v['cz_money']:'0';
            //只有超管能看全部手机号
            if($adminid != 1){
                $v['me_phone'] = hide_phone_number($v['me_phone']);
            }
            if(empty($v['me_parent'])){
                $v['me_parent_word'] = '无上级';$v['me_bind_type_word'] = '无上级';
            }else{
                //查询父级用户信息
                $finfo = $IndexTableModel->getFind('fa_member',"member_id = '{$v['me_parent']}'",'member_id,me_uid,me_nick_name');
                $finfoUid = !empty($finfo)?'('.$finfo['me_uid'].')('.$finfo['me_nick_name'].')':'-';
                $v['me_parent_word'] = $v['me_parent'].$finfoUid;
                if($v['me_bind_type'] == 1){
                    $v['me_bind_type_word'] = '扫码绑定';
                }else{
                    $v['me_bind_type_word'] = '充值绑定';
                }
            }
            switch($v['me_sex']){
                case '0': $v['me_sex_word'] = '未设置';break;
                case '1': $v['me_sex_word'] = '男';break;
                case '2': $v['me_sex_word'] = '女';break;
            }
            switch($v['me_zhuxiao']){
                case '0': $v['me_zhuxiao_word'] = '未注销';break;
                case '1': $v['me_zhuxiao_word'] = '已注销';break;
            }

            switch($v['me_is_real']){
                case '0': $v['me_is_real_word'] = '未认证';break;
                case '1': $v['me_is_real_word'] = '已认证（'.$v['me_realname'].'）';break;
            }

            switch($v['me_is_circle']){
                case '0': $v['me_is_circle_word'] = '未认证';break;
                case '1':
                    if($v['me_car_type'] == 1){
                        $v['me_is_circle_word'] = '私家车辆（'.$v['me_carname'].'）';
                    }
                    if($v['me_car_type'] == 2){
                        $v['me_is_circle_word'] = '企业车辆（'.$v['me_carname'].'）';
                    }
                    if($v['me_car_type'] == 3){
                        $v['me_is_circle_word'] = '运营车辆（'.$v['me_carname'].'）';
                    }
                    break;
            }

            switch($v['me_is_vip']){
                case '0': $v['me_is_vip_word'] = '未开通';break;
                case '1': $v['me_is_vip_word'] = '已开通';break;
            }

            $v['me_add_time'] = date('Y-m-d H:i:s',$v['me_add_time']);
//            if(empty($v['me_area_code'])){
//                $v['me_area_code_word'] = '未获取';
//            }else{
//                $v['me_area_code_word'] = areaCodeToAddress($v['me_area_code']);
//            }

            switch($v['me_zx']){
                case '0': $v['me_zx_word'] = '在线';break;
                case '1': $v['me_zx_word'] = '离线';break;
            }
            return $v;
        });
        $word = '';
        //快手渠道进入总用户数
        $memberNum = Db::table('z_tuiguang_monitoring_ks')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【快手渠道总用户数 ".$memberNum." 】  ";
        //男
        $boymemberNum = Db::table('z_tuiguang_monitoring_ks')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_sex = 1")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【男 ".$boymemberNum." 】  ";
        //女
        $girlmemberNum = Db::table('z_tuiguang_monitoring_ks')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_sex = 2")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【女 ".$girlmemberNum." 】  ";
        //注销
        $zhuxiaomemberNum = Db::table('z_tuiguang_monitoring_ks')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_zhuxiao = 1")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【注销 ".$zhuxiaomemberNum." 】  ";
        //在线
        $zhuxiaomemberNum = Db::table('z_tuiguang_monitoring_ks')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_zx = 0")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【在线 ".$zhuxiaomemberNum." 】  ";

        //充值总金额
        $fhmemberArr = Db::table('z_tuiguang_monitoring_ks')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->join("fa_recharge_stamp_order d",'a.member_id = d.member_id','LEFT')
            ->where('d.id is not null')
            ->where($whehe)
            ->where($whehetime)
            ->group('d.member_id')
            ->column('a.member_id');

        $czallmoney = 0;
        $czrsmoney = 0;
        if(!empty($fhmemberArr)){
            $fhmemberStr = implode(',',$fhmemberArr);
            $czallmoney = Db::table('fa_recharge_stamp_order')->where("`member_id` in ($fhmemberStr)")->where($whehetimecz)->sum('pay_money');
            $czrsmoney = Db::table('fa_recharge_stamp_order')->where("`member_id` in ($fhmemberStr)")->where($whehetimecz)->group('member_id')->count('id');
        }
        $word .= "【充值总金额 ".$czallmoney."元】  【充值人数 ".$czrsmoney."人】";

        //领取视频体验卷人数
        $lqtyjmemberNum = Db::table('z_tuiguang_monitoring_ks')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->join("fa_member_sftyj_log d",'a.member_id = d.member_id','LEFT')
            ->where('d.id is not null')
            ->where($whehe)
            ->where($whehetime)
            ->group('d.member_id')
            ->count('d.member_id');
        //使用视频体验卷
        $sytyjmemberNum = Db::table('z_tuiguang_monitoring_ks')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->join("fa_finance d",'a.member_id = d.member_id','LEFT')
            ->where('d.type = 35 and d.id is not null')
            ->where($whehe)
            ->where($whehetime)
            ->group('d.member_id')
            ->count('d.id');

        $word .= "【领取过体验卷 ".$lqtyjmemberNum."人】  【使用过体验卷 ".$sytyjmemberNum."人】";

//        //充值总金额
//        $czallmoney = Db::table('z_tuiguang_monitoring_ks')
//            ->alias('a')
//            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
//            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
//            ->where($whehe)
//            ->where($whehetime)
//            ->field('(select sum(cz.pay_money) from fa_recharge_stamp_order cz where cz.member_id in (a.member_id)) as cz_money')
//            ->find();
//        var_dump($czallmoney);die;
//        $word .= "【充值总金额 ".$czallmoney." 】  ";

        $lcl_word = '';
        if (isset($param['lcl']) && !empty($param['lcl'])) {
            $lcl_word = $this->getKslcl($param['lcl']);
        }

        $tjword = $this->allTjInfos('z_tuiguang_monitoring_ks','快手');

        //关键词，排序等赋值
        $this->assign($request->get());
        $this->assign([
            'data'  => $data,
            'page'  => $data->render(),
            'total' => $data->total(),
            'word' => $word,
            'lcl_word' => $lcl_word,
            'tjword' => $tjword,
        ]);
        return $this->fetch();
    }




    /**
     * 抖音推广
     * User:@hang
     */
    public function dyindex(Request $request)
    {
        $param = $request->param();
        $whehe = array();
        if (isset($param['member_id']) && !empty($param['member_id'])) {
            $whehe[] = ['b.member_id','=',$param['member_id']];
        }
        if (isset($param['s_member_id']) && !empty($param['s_member_id'])) {
            $whehe[] = ['b.me_parent','=',$param['s_member_id']];
        }
        $whehetime = '';
        if (isset($param['me_add_time']) && !empty($param['me_add_time'])) {
            $time_arr = explode(' - ', $param['me_add_time']);
            $start_time = strtotime($time_arr[0]);
            $end_time = strtotime($time_arr[1]);
            $whehetime = "b.me_add_time >= $start_time AND b.me_add_time <= $end_time";
        }
        if (isset($param['me_zhuxiao']) && $param['me_zhuxiao'] != '') {
            $whehe[] = ['b.me_zhuxiao','=',$param['me_zhuxiao']];
        }
        if (isset($param['me_sex']) && $param['me_sex'] != '') {
            $whehe[] = ['b.me_sex','=',$param['me_sex']];
        }
        if (isset($param['me_zx']) && $param['me_zx'] != '') {
            $whehe[] = ['b.me_zx','=',$param['me_zx']];
        }
        if (isset($param['me_is_vip']) && $param['me_is_vip'] != '') {
            $whehe[] = ['b.me_is_vip','=',$param['me_is_vip']];
        }
        if (isset($param['all_num']) && $param['all_num'] != '') {
            $whehe[] = ['c.all_num','>=',$param['all_num']];
        }
        $order = 'b.me_add_time desc';
        if (isset($param['px']) && $param['px'] != '') {
            switch($param['px']){
                case '1': $order = 'cz_money desc';break;
                case '2': $order = 'wrj_time desc';break;
                case '3': $order = 'c.all_num desc';break;
            }
        }

        $whehetimecz = '';
        $grwhehetimecz = '';
        if (isset($param['cz_add_time']) && !empty($param['cz_add_time'])) {
            $time_arr = explode(' - ', $param['cz_add_time']);
            $start_time = strtotime($time_arr[0]);
            $end_time = strtotime($time_arr[1]);
            $whehetimecz = "add_time >= $start_time AND add_time <= $end_time";
            $grwhehetimecz = " and cz.add_time >= $start_time and cz.add_time <= $end_time";
        }

        $whehe[] = ['a.member_id','neq',0];
        $IndexTableModel = New IndexTableModel();
        $data = Db::table('z_tuiguang_monitoring_dy')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->join("fa_member_sftyj_log d",'a.member_id = d.member_id','LEFT')
            ->join("fa_member_jx e",'a.member_id = e.member_id','LEFT')
            ->where($whehe)
            ->where($whehetime)
            ->field('a.id as tg_id,a.type as tg_type,a.accountid as tg_accountid,a.aid as tg_aid,a.member_id,b.me_uid,b.me_phone,b.me_add_time,b.me_nick_name,b.me_img,b.me_parent,b.me_bind_type,b.me_bind_time,b.me_sex,b.me_zx,b.me_xn_zx,b.me_status,b.me_zhuxiao,b.me_is_real,b.me_realname,b.me_is_vip,b.me_area_code,b.me_is_circle,b.me_carname,b.me_circle_id,b.me_car_type,c.w_id,c.w_num,c.all_num,c.s_list,(select sum(wrj.stay_num) from fa_stay_software wrj where a.member_id = wrj.member_id) as wrj_time,(select sum(ssp.stay_num) from fa_stay_video ssp where a.member_id = ssp.member_id) as ssp_time,(select sum(cz.pay_money) from fa_recharge_stamp_order cz where a.member_id = cz.member_id'.$grwhehetimecz.') as cz_money,(select count(cz.id) from fa_recharge_stamp_order cz where a.member_id = cz.member_id'.$grwhehetimecz.') as cz_num,d.id as ling_id,e.id as jx,e.apk_number,e.datetime')
            ->order($order)
            ->paginate($this->admin['per_page'],false,['query'=>request()->param()]);

        $adminid = $this->uid;
        $data->each(function ($v, $k)use($IndexTableModel,$adminid) {
            $v['ling_word'] = '未领';
            if(!empty($v['ling_id'])){
                $v['ling_word'] = '已领';
            }
            $v['jx_word'] = '未访问';
            if(!empty($v['jx'])){
                $v['jx_word'] = '版本号'.$v['apk_number'].' / '.$v['datetime'];
            }
            $v['tr_color'] = 0;
            if(!empty($v['cz_money'])){
                $v['tr_color'] = 1;//充值显示绿色行
            }
            if($v['wrj_time'] < $v['ssp_time']){
                $v['wrj_time'] = $v['ssp_time'];
            }
            $v['wrj_time'] = secondChanage($v['wrj_time']);
            $v['ssp_time'] = secondChanage($v['ssp_time']);
            $v['cz_money'] = !empty($v['cz_money'])?$v['cz_money']:'0';
            //只有超管能看全部手机号
            if($adminid != 1){
                $v['me_phone'] = hide_phone_number($v['me_phone']);
            }
            if(empty($v['me_parent'])){
                $v['me_parent_word'] = '无上级';$v['me_bind_type_word'] = '无上级';
            }else{
                //查询父级用户信息
                $finfo = $IndexTableModel->getFind('fa_member',"member_id = '{$v['me_parent']}'",'member_id,me_uid,me_nick_name');
                $finfoUid = !empty($finfo)?'('.$finfo['me_uid'].')('.$finfo['me_nick_name'].')':'-';
                $v['me_parent_word'] = $v['me_parent'].$finfoUid;
                if($v['me_bind_type'] == 1){
                    $v['me_bind_type_word'] = '扫码绑定';
                }else{
                    $v['me_bind_type_word'] = '充值绑定';
                }
            }
            switch($v['me_sex']){
                case '0': $v['me_sex_word'] = '未设置';break;
                case '1': $v['me_sex_word'] = '男';break;
                case '2': $v['me_sex_word'] = '女';break;
            }
            switch($v['me_zhuxiao']){
                case '0': $v['me_zhuxiao_word'] = '未注销';break;
                case '1': $v['me_zhuxiao_word'] = '已注销';break;
            }

            switch($v['me_is_real']){
                case '0': $v['me_is_real_word'] = '未认证';break;
                case '1': $v['me_is_real_word'] = '已认证（'.$v['me_realname'].'）';break;
            }

            switch($v['me_is_circle']){
                case '0': $v['me_is_circle_word'] = '未认证';break;
                case '1':
                    if($v['me_car_type'] == 1){
                        $v['me_is_circle_word'] = '私家车辆（'.$v['me_carname'].'）';
                    }
                    if($v['me_car_type'] == 2){
                        $v['me_is_circle_word'] = '企业车辆（'.$v['me_carname'].'）';
                    }
                    if($v['me_car_type'] == 3){
                        $v['me_is_circle_word'] = '运营车辆（'.$v['me_carname'].'）';
                    }
                    break;
            }

            switch($v['me_is_vip']){
                case '0': $v['me_is_vip_word'] = '未开通';break;
                case '1': $v['me_is_vip_word'] = '已开通';break;
            }

            $v['me_add_time'] = date('Y-m-d H:i:s',$v['me_add_time']);
//            if(empty($v['me_area_code'])){
//                $v['me_area_code_word'] = '未获取';
//            }else{
//                $v['me_area_code_word'] = areaCodeToAddress($v['me_area_code']);
//            }

            switch($v['me_zx']){
                case '0': $v['me_zx_word'] = '在线';break;
                case '1': $v['me_zx_word'] = '离线';break;
            }
            return $v;
        });
        $word = '';
        //抖音渠道进入总用户数
        $memberNum = Db::table('z_tuiguang_monitoring_dy')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【抖音渠道总用户数 ".$memberNum." 】  ";
        //男
        $boymemberNum = Db::table('z_tuiguang_monitoring_dy')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_sex = 1")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【男 ".$boymemberNum." 】  ";
        //女
        $girlmemberNum = Db::table('z_tuiguang_monitoring_dy')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_sex = 2")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【女 ".$girlmemberNum." 】  ";
        //注销
        $zhuxiaomemberNum = Db::table('z_tuiguang_monitoring_dy')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_zhuxiao = 1")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【注销 ".$zhuxiaomemberNum." 】  ";
        //在线
        $zhuxiaomemberNum = Db::table('z_tuiguang_monitoring_dy')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_zx = 0")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【在线 ".$zhuxiaomemberNum." 】  ";

        //充值总金额
        $fhmemberArr = Db::table('z_tuiguang_monitoring_dy')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->join("fa_recharge_stamp_order d",'a.member_id = d.member_id','LEFT')
            ->where('d.id is not null')
            ->where($whehe)
            ->where($whehetime)
            ->group('d.member_id')
            ->column('a.member_id');

        $czallmoney = 0;
        $czrsmoney = 0;
        if(!empty($fhmemberArr)){
            $fhmemberStr = implode(',',$fhmemberArr);
            $czallmoney = Db::table('fa_recharge_stamp_order')->where("`member_id` in ($fhmemberStr)")->where($whehetimecz)->sum('pay_money');
            $czrsmoney = Db::table('fa_recharge_stamp_order')->where("`member_id` in ($fhmemberStr)")->where($whehetimecz)->group('member_id')->count('id');
        }
        $word .= "【充值总金额 ".$czallmoney."元】  【充值人数 ".$czrsmoney."人】";

        //领取视频体验卷人数
        $lqtyjmemberNum = Db::table('z_tuiguang_monitoring_dy')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->join("fa_member_sftyj_log d",'a.member_id = d.member_id','LEFT')
            ->where('d.id is not null')
            ->where($whehe)
            ->where($whehetime)
            ->group('d.member_id')
            ->count('d.member_id');
        //使用视频体验卷
        $sytyjmemberNum = Db::table('z_tuiguang_monitoring_dy')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->join("fa_finance d",'a.member_id = d.member_id','LEFT')
            ->where('d.type = 35 and d.id is not null')
            ->where($whehe)
            ->where($whehetime)
            ->group('d.member_id')
            ->count('d.id');

        $word .= "【领取过体验卷 ".$lqtyjmemberNum."人】  【使用过体验卷 ".$sytyjmemberNum."人】";

//        //充值总金额
//        $czallmoney = Db::table('z_tuiguang_monitoring_dy')
//            ->alias('a')
//            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
//            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
//            ->where($whehe)
//            ->where($whehetime)
//            ->field('(select sum(cz.pay_money) from fa_recharge_stamp_order cz where cz.member_id in (a.member_id)) as cz_money')
//            ->find();
//        var_dump($czallmoney);die;
//        $word .= "【充值总金额 ".$czallmoney." 】  ";

        $lcl_word = '';
        if (isset($param['lcl']) && !empty($param['lcl'])) {
            $lcl_word = $this->getDylcl($param['lcl']);
        }

        $tjword = $this->allTjInfos('z_tuiguang_monitoring_dy','抖音');

        //关键词，排序等赋值
        $this->assign($request->get());
        $this->assign([
            'data'  => $data,
            'page'  => $data->render(),
            'total' => $data->total(),
            'word' => $word,
            'lcl_word' => $lcl_word,
            'tjword' => $tjword,
        ]);
        return $this->fetch();
    }



    /**
     * vivo推广
     * User:@hang
     */
    public function vivoindex(Request $request)
    {
        $param = $request->param();
        $whehe = array();
        if (isset($param['member_id']) && !empty($param['member_id'])) {
            $whehe[] = ['b.member_id','=',$param['member_id']];
        }
        if (isset($param['s_member_id']) && !empty($param['s_member_id'])) {
            $whehe[] = ['b.me_parent','=',$param['s_member_id']];
        }
        $whehetime = '';
        if (isset($param['me_add_time']) && !empty($param['me_add_time'])) {
            $time_arr = explode(' - ', $param['me_add_time']);
            $start_time = strtotime($time_arr[0]);
            $end_time = strtotime($time_arr[1]);
            $whehetime = "b.me_add_time >= $start_time AND b.me_add_time <= $end_time";
        }
        if (isset($param['me_zhuxiao']) && $param['me_zhuxiao'] != '') {
            $whehe[] = ['b.me_zhuxiao','=',$param['me_zhuxiao']];
        }
        if (isset($param['me_sex']) && $param['me_sex'] != '') {
            $whehe[] = ['b.me_sex','=',$param['me_sex']];
        }
        if (isset($param['me_zx']) && $param['me_zx'] != '') {
            $whehe[] = ['b.me_zx','=',$param['me_zx']];
        }
        if (isset($param['me_is_vip']) && $param['me_is_vip'] != '') {
            $whehe[] = ['b.me_is_vip','=',$param['me_is_vip']];
        }
        if (isset($param['all_num']) && $param['all_num'] != '') {
            $whehe[] = ['c.all_num','>=',$param['all_num']];
        }
        $order = 'b.me_add_time desc';
        if (isset($param['px']) && $param['px'] != '') {
            switch($param['px']){
                case '1': $order = 'cz_money desc';break;
                case '2': $order = 'wrj_time desc';break;
                case '3': $order = 'c.all_num desc';break;
            }
        }

        $whehetimecz = '';
        $grwhehetimecz = '';
        if (isset($param['cz_add_time']) && !empty($param['cz_add_time'])) {
            $time_arr = explode(' - ', $param['cz_add_time']);
            $start_time = strtotime($time_arr[0]);
            $end_time = strtotime($time_arr[1]);
            $whehetimecz = "add_time >= $start_time AND add_time <= $end_time";
            $grwhehetimecz = " and cz.add_time >= $start_time and cz.add_time <= $end_time";
        }

        $whehe[] = ['a.member_id','neq',0];
        $IndexTableModel = New IndexTableModel();
        $data = Db::table('z_tuiguang_monitoring_vivo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where($whehe)
            ->where($whehetime)
            ->field('a.id as tg_id,a.type as tg_type,a.accountid as tg_accountid,a.aid as tg_aid,a.member_id,b.me_uid,b.me_phone,b.me_add_time,b.me_nick_name,b.me_img,b.me_parent,b.me_bind_type,b.me_bind_time,b.me_sex,b.me_zx,b.me_xn_zx,b.me_status,b.me_zhuxiao,b.me_is_real,b.me_realname,b.me_is_vip,b.me_area_code,b.me_is_circle,b.me_carname,b.me_circle_id,b.me_car_type,c.w_id,c.w_num,c.all_num,c.s_list,(select sum(wrj.stay_num) from fa_stay_software wrj where a.member_id = wrj.member_id) as wrj_time,(select sum(ssp.stay_num) from fa_stay_video ssp where a.member_id = ssp.member_id) as ssp_time,(select sum(cz.pay_money) from fa_recharge_stamp_order cz where a.member_id = cz.member_id'.$grwhehetimecz.') as cz_money,(select count(cz.id) from fa_recharge_stamp_order cz where a.member_id = cz.member_id'.$grwhehetimecz.') as cz_num')
            ->order($order)
            ->paginate($this->admin['per_page'],false,['query'=>request()->param()]);

        $adminid = $this->uid;
        $data->each(function ($v, $k)use($IndexTableModel,$adminid) {
            $v['tr_color'] = 0;
            if(!empty($v['cz_money'])){
                $v['tr_color'] = 1;//充值显示绿色行
            }
            if($v['wrj_time'] < $v['ssp_time']){
                $v['wrj_time'] = $v['ssp_time'];
            }
            $v['wrj_time'] = secondChanage($v['wrj_time']);
            $v['ssp_time'] = secondChanage($v['ssp_time']);
            $v['cz_money'] = !empty($v['cz_money'])?$v['cz_money']:'0';
            //只有超管能看全部手机号
            if($adminid != 1){
                $v['me_phone'] = hide_phone_number($v['me_phone']);
            }
            if(empty($v['me_parent'])){
                $v['me_parent_word'] = '无上级';$v['me_bind_type_word'] = '无上级';
            }else{
                //查询父级用户信息
                $finfo = $IndexTableModel->getFind('fa_member',"member_id = '{$v['me_parent']}'",'member_id,me_uid,me_nick_name');
                $finfoUid = !empty($finfo)?'('.$finfo['me_uid'].')('.$finfo['me_nick_name'].')':'-';
                $v['me_parent_word'] = $v['me_parent'].$finfoUid;
                if($v['me_bind_type'] == 1){
                    $v['me_bind_type_word'] = '扫码绑定';
                }else{
                    $v['me_bind_type_word'] = '充值绑定';
                }
            }
            switch($v['me_sex']){
                case '0': $v['me_sex_word'] = '未设置';break;
                case '1': $v['me_sex_word'] = '男';break;
                case '2': $v['me_sex_word'] = '女';break;
            }
            switch($v['me_zhuxiao']){
                case '0': $v['me_zhuxiao_word'] = '未注销';break;
                case '1': $v['me_zhuxiao_word'] = '已注销';break;
            }

            switch($v['me_is_real']){
                case '0': $v['me_is_real_word'] = '未认证';break;
                case '1': $v['me_is_real_word'] = '已认证（'.$v['me_realname'].'）';break;
            }

            switch($v['me_is_circle']){
                case '0': $v['me_is_circle_word'] = '未认证';break;
                case '1':
                    if($v['me_car_type'] == 1){
                        $v['me_is_circle_word'] = '私家车辆（'.$v['me_carname'].'）';
                    }
                    if($v['me_car_type'] == 2){
                        $v['me_is_circle_word'] = '企业车辆（'.$v['me_carname'].'）';
                    }
                    if($v['me_car_type'] == 3){
                        $v['me_is_circle_word'] = '运营车辆（'.$v['me_carname'].'）';
                    }
                    break;
            }

            switch($v['me_is_vip']){
                case '0': $v['me_is_vip_word'] = '未开通';break;
                case '1': $v['me_is_vip_word'] = '已开通';break;
            }

            $v['me_add_time'] = date('Y-m-d H:i:s',$v['me_add_time']);
//            if(empty($v['me_area_code'])){
//                $v['me_area_code_word'] = '未获取';
//            }else{
//                $v['me_area_code_word'] = areaCodeToAddress($v['me_area_code']);
//            }

            switch($v['me_zx']){
                case '0': $v['me_zx_word'] = '在线';break;
                case '1': $v['me_zx_word'] = '离线';break;
            }
            return $v;
        });
        $word = '';
        //vivo渠道进入总用户数
        $memberNum = Db::table('z_tuiguang_monitoring_vivo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【vivo渠道总用户数 ".$memberNum." 】  ";
        //男
        $boymemberNum = Db::table('z_tuiguang_monitoring_vivo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_sex = 1")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【男 ".$boymemberNum." 】  ";
        //女
        $girlmemberNum = Db::table('z_tuiguang_monitoring_vivo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_sex = 2")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【女 ".$girlmemberNum." 】  ";
        //注销
        $zhuxiaomemberNum = Db::table('z_tuiguang_monitoring_vivo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_zhuxiao = 1")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【注销 ".$zhuxiaomemberNum." 】  ";
        //在线
        $zhuxiaomemberNum = Db::table('z_tuiguang_monitoring_vivo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_zx = 0")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【在线 ".$zhuxiaomemberNum." 】  ";

        //充值总金额
        $fhmemberArr = Db::table('z_tuiguang_monitoring_vivo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->join("fa_recharge_stamp_order d",'a.member_id = d.member_id','LEFT')
            ->where('d.id is not null')
            ->where($whehe)
            ->where($whehetime)
            ->group('d.member_id')
            ->column('a.member_id');

        $czallmoney = 0;
        $czrsmoney = 0;
        if(!empty($fhmemberArr)){
            $fhmemberStr = implode(',',$fhmemberArr);
            $czallmoney = Db::table('fa_recharge_stamp_order')->where("`member_id` in ($fhmemberStr)")->where($whehetimecz)->sum('pay_money');
            $czrsmoney = Db::table('fa_recharge_stamp_order')->where("`member_id` in ($fhmemberStr)")->where($whehetimecz)->group('member_id')->count('id');
        }
        $word .= "【充值总金额 ".$czallmoney."元】  【充值人数 ".$czrsmoney."人】";

        //领取视频体验卷人数
        $lqtyjmemberNum = Db::table('z_tuiguang_monitoring_vivo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->join("fa_member_sftyj_log d",'a.member_id = d.member_id','LEFT')
            ->where('d.id is not null')
            ->where($whehe)
            ->where($whehetime)
            ->group('d.member_id')
            ->count('d.member_id');
        //使用视频体验卷
        $sytyjmemberNum = Db::table('z_tuiguang_monitoring_vivo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->join("fa_finance d",'a.member_id = d.member_id','LEFT')
            ->where('d.type = 35 and d.id is not null')
            ->where($whehe)
            ->where($whehetime)
            ->group('d.member_id')
            ->count('d.id');

        $word .= "【领取过体验卷 ".$lqtyjmemberNum."人】  【使用过体验卷 ".$sytyjmemberNum."人】";

//        //充值总金额
//        $czallmoney = Db::table('z_tuiguang_monitoring_vivo')
//            ->alias('a')
//            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
//            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
//            ->where($whehe)
//            ->where($whehetime)
//            ->field('(select sum(cz.pay_money) from fa_recharge_stamp_order cz where cz.member_id in (a.member_id)) as cz_money')
//            ->find();
//        var_dump($czallmoney);die;
//        $word .= "【充值总金额 ".$czallmoney." 】  ";

        $lcl_word = '';
        if (isset($param['lcl']) && !empty($param['lcl'])) {
            $lcl_word = $this->getVivolcl($param['lcl']);
        }

        $tjword = $this->allTjInfos('z_tuiguang_monitoring_vivo','vivo');

        //关键词，排序等赋值
        $this->assign($request->get());
        $this->assign([
            'data'  => $data,
            'page'  => $data->render(),
            'total' => $data->total(),
            'word' => $word,
            'lcl_word' => $lcl_word,
            'tjword' => $tjword,
        ]);
        return $this->fetch();
    }



    /**
     * oppo推广
     * User:@hang
     */
    public function oppoindex(Request $request)
    {
        $param = $request->param();
        $whehe = array();
        if (isset($param['member_id']) && !empty($param['member_id'])) {
            $whehe[] = ['b.member_id','=',$param['member_id']];
        }
        if (isset($param['s_member_id']) && !empty($param['s_member_id'])) {
            $whehe[] = ['b.me_parent','=',$param['s_member_id']];
        }
        $whehetime = '';
        if (isset($param['me_add_time']) && !empty($param['me_add_time'])) {
            $time_arr = explode(' - ', $param['me_add_time']);
            $start_time = strtotime($time_arr[0]);
            $end_time = strtotime($time_arr[1]);
            $whehetime = "b.me_add_time >= $start_time AND b.me_add_time <= $end_time";
        }
        if (isset($param['me_zhuxiao']) && $param['me_zhuxiao'] != '') {
            $whehe[] = ['b.me_zhuxiao','=',$param['me_zhuxiao']];
        }
        if (isset($param['me_sex']) && $param['me_sex'] != '') {
            $whehe[] = ['b.me_sex','=',$param['me_sex']];
        }
        if (isset($param['me_zx']) && $param['me_zx'] != '') {
            $whehe[] = ['b.me_zx','=',$param['me_zx']];
        }
        if (isset($param['me_is_vip']) && $param['me_is_vip'] != '') {
            $whehe[] = ['b.me_is_vip','=',$param['me_is_vip']];
        }
        if (isset($param['all_num']) && $param['all_num'] != '') {
            $whehe[] = ['c.all_num','>=',$param['all_num']];
        }
        $order = 'b.me_add_time desc';
        if (isset($param['px']) && $param['px'] != '') {
            switch($param['px']){
                case '1': $order = 'cz_money desc';break;
                case '2': $order = 'wrj_time desc';break;
                case '3': $order = 'c.all_num desc';break;
            }
        }

        $whehetimecz = '';
        $grwhehetimecz = '';
        if (isset($param['cz_add_time']) && !empty($param['cz_add_time'])) {
            $time_arr = explode(' - ', $param['cz_add_time']);
            $start_time = strtotime($time_arr[0]);
            $end_time = strtotime($time_arr[1]);
            $whehetimecz = "add_time >= $start_time AND add_time <= $end_time";
            $grwhehetimecz = " and cz.add_time >= $start_time and cz.add_time <= $end_time";
        }

        $whehe[] = ['a.member_id','neq',0];
        $IndexTableModel = New IndexTableModel();
        $data = Db::table('z_tuiguang_monitoring_oppo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where($whehe)
            ->where($whehetime)
            ->field('a.id as tg_id,a.type as tg_type,a.accountid as tg_accountid,a.aid as tg_aid,a.member_id,b.me_uid,b.me_phone,b.me_add_time,b.me_nick_name,b.me_img,b.me_parent,b.me_bind_type,b.me_bind_time,b.me_sex,b.me_zx,b.me_xn_zx,b.me_status,b.me_zhuxiao,b.me_is_real,b.me_realname,b.me_is_vip,b.me_area_code,b.me_is_circle,b.me_carname,b.me_circle_id,b.me_car_type,c.w_id,c.w_num,c.all_num,c.s_list,(select sum(wrj.stay_num) from fa_stay_software wrj where a.member_id = wrj.member_id) as wrj_time,(select sum(ssp.stay_num) from fa_stay_video ssp where a.member_id = ssp.member_id) as ssp_time,(select sum(cz.pay_money) from fa_recharge_stamp_order cz where a.member_id = cz.member_id'.$grwhehetimecz.') as cz_money,(select count(cz.id) from fa_recharge_stamp_order cz where a.member_id = cz.member_id'.$grwhehetimecz.') as cz_num')
            ->order($order)
            ->paginate($this->admin['per_page'],false,['query'=>request()->param()]);

        $adminid = $this->uid;
        $data->each(function ($v, $k)use($IndexTableModel,$adminid) {
            $v['tr_color'] = 0;
            if(!empty($v['cz_money'])){
                $v['tr_color'] = 1;//充值显示绿色行
            }
            if($v['wrj_time'] < $v['ssp_time']){
                $v['wrj_time'] = $v['ssp_time'];
            }
            $v['wrj_time'] = secondChanage($v['wrj_time']);
            $v['ssp_time'] = secondChanage($v['ssp_time']);
            $v['cz_money'] = !empty($v['cz_money'])?$v['cz_money']:'0';
            //只有超管能看全部手机号
            if($adminid != 1){
                $v['me_phone'] = hide_phone_number($v['me_phone']);
            }
            if(empty($v['me_parent'])){
                $v['me_parent_word'] = '无上级';$v['me_bind_type_word'] = '无上级';
            }else{
                //查询父级用户信息
                $finfo = $IndexTableModel->getFind('fa_member',"member_id = '{$v['me_parent']}'",'member_id,me_uid,me_nick_name');
                $finfoUid = !empty($finfo)?'('.$finfo['me_uid'].')('.$finfo['me_nick_name'].')':'-';
                $v['me_parent_word'] = $v['me_parent'].$finfoUid;
                if($v['me_bind_type'] == 1){
                    $v['me_bind_type_word'] = '扫码绑定';
                }else{
                    $v['me_bind_type_word'] = '充值绑定';
                }
            }
            switch($v['me_sex']){
                case '0': $v['me_sex_word'] = '未设置';break;
                case '1': $v['me_sex_word'] = '男';break;
                case '2': $v['me_sex_word'] = '女';break;
            }
            switch($v['me_zhuxiao']){
                case '0': $v['me_zhuxiao_word'] = '未注销';break;
                case '1': $v['me_zhuxiao_word'] = '已注销';break;
            }

            switch($v['me_is_real']){
                case '0': $v['me_is_real_word'] = '未认证';break;
                case '1': $v['me_is_real_word'] = '已认证（'.$v['me_realname'].'）';break;
            }

            switch($v['me_is_circle']){
                case '0': $v['me_is_circle_word'] = '未认证';break;
                case '1':
                    if($v['me_car_type'] == 1){
                        $v['me_is_circle_word'] = '私家车辆（'.$v['me_carname'].'）';
                    }
                    if($v['me_car_type'] == 2){
                        $v['me_is_circle_word'] = '企业车辆（'.$v['me_carname'].'）';
                    }
                    if($v['me_car_type'] == 3){
                        $v['me_is_circle_word'] = '运营车辆（'.$v['me_carname'].'）';
                    }
                    break;
            }

            switch($v['me_is_vip']){
                case '0': $v['me_is_vip_word'] = '未开通';break;
                case '1': $v['me_is_vip_word'] = '已开通';break;
            }

            $v['me_add_time'] = date('Y-m-d H:i:s',$v['me_add_time']);
//            if(empty($v['me_area_code'])){
//                $v['me_area_code_word'] = '未获取';
//            }else{
//                $v['me_area_code_word'] = areaCodeToAddress($v['me_area_code']);
//            }

            switch($v['me_zx']){
                case '0': $v['me_zx_word'] = '在线';break;
                case '1': $v['me_zx_word'] = '离线';break;
            }
            return $v;
        });
        $word = '';
        //oppo渠道进入总用户数
        $memberNum = Db::table('z_tuiguang_monitoring_oppo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【oppo渠道总用户数 ".$memberNum." 】  ";
        //男
        $boymemberNum = Db::table('z_tuiguang_monitoring_oppo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_sex = 1")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【男 ".$boymemberNum." 】  ";
        //女
        $girlmemberNum = Db::table('z_tuiguang_monitoring_oppo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_sex = 2")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【女 ".$girlmemberNum." 】  ";
        //注销
        $zhuxiaomemberNum = Db::table('z_tuiguang_monitoring_oppo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_zhuxiao = 1")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【注销 ".$zhuxiaomemberNum." 】  ";
        //在线
        $zhuxiaomemberNum = Db::table('z_tuiguang_monitoring_oppo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_zx = 0")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【在线 ".$zhuxiaomemberNum." 】  ";

        //充值总金额
        $fhmemberArr = Db::table('z_tuiguang_monitoring_oppo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->join("fa_recharge_stamp_order d",'a.member_id = d.member_id','LEFT')
            ->where('d.id is not null')
            ->where($whehe)
            ->where($whehetime)
            ->group('d.member_id')
            ->column('a.member_id');

        $czallmoney = 0;
        $czrsmoney = 0;
        if(!empty($fhmemberArr)){
            $fhmemberStr = implode(',',$fhmemberArr);
            $czallmoney = Db::table('fa_recharge_stamp_order')->where("`member_id` in ($fhmemberStr)")->where($whehetimecz)->sum('pay_money');
            $czrsmoney = Db::table('fa_recharge_stamp_order')->where("`member_id` in ($fhmemberStr)")->where($whehetimecz)->group('member_id')->count('id');
        }
        $word .= "【充值总金额 ".$czallmoney."元】  【充值人数 ".$czrsmoney."人】";

        //领取视频体验卷人数
        $lqtyjmemberNum = Db::table('z_tuiguang_monitoring_oppo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->join("fa_member_sftyj_log d",'a.member_id = d.member_id','LEFT')
            ->where('d.id is not null')
            ->where($whehe)
            ->where($whehetime)
            ->group('d.member_id')
            ->count('d.member_id');
        //使用视频体验卷
        $sytyjmemberNum = Db::table('z_tuiguang_monitoring_oppo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->join("fa_finance d",'a.member_id = d.member_id','LEFT')
            ->where('d.type = 35 and d.id is not null')
            ->where($whehe)
            ->where($whehetime)
            ->group('d.member_id')
            ->count('d.id');

        $word .= "【领取过体验卷 ".$lqtyjmemberNum."人】  【使用过体验卷 ".$sytyjmemberNum."人】";

//        //充值总金额
//        $czallmoney = Db::table('z_tuiguang_monitoring_oppo')
//            ->alias('a')
//            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
//            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
//            ->where($whehe)
//            ->where($whehetime)
//            ->field('(select sum(cz.pay_money) from fa_recharge_stamp_order cz where cz.member_id in (a.member_id)) as cz_money')
//            ->find();
//        var_dump($czallmoney);die;
//        $word .= "【充值总金额 ".$czallmoney." 】  ";

        $lcl_word = '';
        if (isset($param['lcl']) && !empty($param['lcl'])) {
            $lcl_word = $this->getOppolcl($param['lcl']);
        }

        $tjword = $this->allTjInfos('z_tuiguang_monitoring_oppo','oppo');

        //关键词，排序等赋值
        $this->assign($request->get());
        $this->assign([
            'data'  => $data,
            'page'  => $data->render(),
            'total' => $data->total(),
            'word' => $word,
            'lcl_word' => $lcl_word,
            'tjword' => $tjword,
        ]);
        return $this->fetch();
    }



    /**
     * 小米推广
     * User:@hang
     */
    public function xiaomiindex(Request $request)
    {
        $param = $request->param();
        $whehe = array();
        if (isset($param['member_id']) && !empty($param['member_id'])) {
            $whehe[] = ['b.member_id','=',$param['member_id']];
        }
        if (isset($param['s_member_id']) && !empty($param['s_member_id'])) {
            $whehe[] = ['b.me_parent','=',$param['s_member_id']];
        }
        $whehetime = '';
        if (isset($param['me_add_time']) && !empty($param['me_add_time'])) {
            $time_arr = explode(' - ', $param['me_add_time']);
            $start_time = strtotime($time_arr[0]);
            $end_time = strtotime($time_arr[1]);
            $whehetime = "b.me_add_time >= $start_time AND b.me_add_time <= $end_time";
        }
        if (isset($param['me_zhuxiao']) && $param['me_zhuxiao'] != '') {
            $whehe[] = ['b.me_zhuxiao','=',$param['me_zhuxiao']];
        }
        if (isset($param['me_sex']) && $param['me_sex'] != '') {
            $whehe[] = ['b.me_sex','=',$param['me_sex']];
        }
        if (isset($param['me_zx']) && $param['me_zx'] != '') {
            $whehe[] = ['b.me_zx','=',$param['me_zx']];
        }
        if (isset($param['me_is_vip']) && $param['me_is_vip'] != '') {
            $whehe[] = ['b.me_is_vip','=',$param['me_is_vip']];
        }
        if (isset($param['all_num']) && $param['all_num'] != '') {
            $whehe[] = ['c.all_num','>=',$param['all_num']];
        }
        $order = 'b.me_add_time desc';
        if (isset($param['px']) && $param['px'] != '') {
            switch($param['px']){
                case '1': $order = 'cz_money desc';break;
                case '2': $order = 'wrj_time desc';break;
                case '3': $order = 'c.all_num desc';break;
            }
        }

        $whehetimecz = '';
        $grwhehetimecz = '';
        if (isset($param['cz_add_time']) && !empty($param['cz_add_time'])) {
            $time_arr = explode(' - ', $param['cz_add_time']);
            $start_time = strtotime($time_arr[0]);
            $end_time = strtotime($time_arr[1]);
            $whehetimecz = "add_time >= $start_time AND add_time <= $end_time";
            $grwhehetimecz = " and cz.add_time >= $start_time and cz.add_time <= $end_time";
        }

        $whehe[] = ['a.member_id','neq',0];
        $IndexTableModel = New IndexTableModel();
        $data = Db::table('z_tuiguang_monitoring_xiaomi')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where($whehe)
            ->where($whehetime)
            ->field('a.id as tg_id,a.type as tg_type,a.accountid as tg_accountid,a.aid as tg_aid,a.member_id,b.me_uid,b.me_phone,b.me_add_time,b.me_nick_name,b.me_img,b.me_parent,b.me_bind_type,b.me_bind_time,b.me_sex,b.me_zx,b.me_xn_zx,b.me_status,b.me_zhuxiao,b.me_is_real,b.me_realname,b.me_is_vip,b.me_area_code,b.me_is_circle,b.me_carname,b.me_circle_id,b.me_car_type,c.w_id,c.w_num,c.all_num,c.s_list,(select sum(wrj.stay_num) from fa_stay_software wrj where a.member_id = wrj.member_id) as wrj_time,(select sum(ssp.stay_num) from fa_stay_video ssp where a.member_id = ssp.member_id) as ssp_time,(select sum(cz.pay_money) from fa_recharge_stamp_order cz where a.member_id = cz.member_id'.$grwhehetimecz.') as cz_money,(select count(cz.id) from fa_recharge_stamp_order cz where a.member_id = cz.member_id'.$grwhehetimecz.') as cz_num')
            ->order($order)
            ->paginate($this->admin['per_page'],false,['query'=>request()->param()]);

        $adminid = $this->uid;
        $data->each(function ($v, $k)use($IndexTableModel,$adminid) {
            $v['tr_color'] = 0;
            if(!empty($v['cz_money'])){
                $v['tr_color'] = 1;//充值显示绿色行
            }
            if($v['wrj_time'] < $v['ssp_time']){
                $v['wrj_time'] = $v['ssp_time'];
            }
            $v['wrj_time'] = secondChanage($v['wrj_time']);
            $v['ssp_time'] = secondChanage($v['ssp_time']);
            $v['cz_money'] = !empty($v['cz_money'])?$v['cz_money']:'0';
            //只有超管能看全部手机号
            if($adminid != 1){
                $v['me_phone'] = hide_phone_number($v['me_phone']);
            }
            if(empty($v['me_parent'])){
                $v['me_parent_word'] = '无上级';$v['me_bind_type_word'] = '无上级';
            }else{
                //查询父级用户信息
                $finfo = $IndexTableModel->getFind('fa_member',"member_id = '{$v['me_parent']}'",'member_id,me_uid,me_nick_name');
                $finfoUid = !empty($finfo)?'('.$finfo['me_uid'].')('.$finfo['me_nick_name'].')':'-';
                $v['me_parent_word'] = $v['me_parent'].$finfoUid;
                if($v['me_bind_type'] == 1){
                    $v['me_bind_type_word'] = '扫码绑定';
                }else{
                    $v['me_bind_type_word'] = '充值绑定';
                }
            }
            switch($v['me_sex']){
                case '0': $v['me_sex_word'] = '未设置';break;
                case '1': $v['me_sex_word'] = '男';break;
                case '2': $v['me_sex_word'] = '女';break;
            }
            switch($v['me_zhuxiao']){
                case '0': $v['me_zhuxiao_word'] = '未注销';break;
                case '1': $v['me_zhuxiao_word'] = '已注销';break;
            }

            switch($v['me_is_real']){
                case '0': $v['me_is_real_word'] = '未认证';break;
                case '1': $v['me_is_real_word'] = '已认证（'.$v['me_realname'].'）';break;
            }

            switch($v['me_is_circle']){
                case '0': $v['me_is_circle_word'] = '未认证';break;
                case '1':
                    if($v['me_car_type'] == 1){
                        $v['me_is_circle_word'] = '私家车辆（'.$v['me_carname'].'）';
                    }
                    if($v['me_car_type'] == 2){
                        $v['me_is_circle_word'] = '企业车辆（'.$v['me_carname'].'）';
                    }
                    if($v['me_car_type'] == 3){
                        $v['me_is_circle_word'] = '运营车辆（'.$v['me_carname'].'）';
                    }
                    break;
            }

            switch($v['me_is_vip']){
                case '0': $v['me_is_vip_word'] = '未开通';break;
                case '1': $v['me_is_vip_word'] = '已开通';break;
            }

            $v['me_add_time'] = date('Y-m-d H:i:s',$v['me_add_time']);
//            if(empty($v['me_area_code'])){
//                $v['me_area_code_word'] = '未获取';
//            }else{
//                $v['me_area_code_word'] = areaCodeToAddress($v['me_area_code']);
//            }

            switch($v['me_zx']){
                case '0': $v['me_zx_word'] = '在线';break;
                case '1': $v['me_zx_word'] = '离线';break;
            }
            return $v;
        });
        $word = '';
        //小米渠道进入总用户数
        $memberNum = Db::table('z_tuiguang_monitoring_xiaomi')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【小米渠道总用户数 ".$memberNum." 】  ";
        //男
        $boymemberNum = Db::table('z_tuiguang_monitoring_xiaomi')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_sex = 1")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【男 ".$boymemberNum." 】  ";
        //女
        $girlmemberNum = Db::table('z_tuiguang_monitoring_xiaomi')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_sex = 2")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【女 ".$girlmemberNum." 】  ";
        //注销
        $zhuxiaomemberNum = Db::table('z_tuiguang_monitoring_xiaomi')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_zhuxiao = 1")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【注销 ".$zhuxiaomemberNum." 】  ";
        //在线
        $zhuxiaomemberNum = Db::table('z_tuiguang_monitoring_xiaomi')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_zx = 0")
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');
        $word .= "【在线 ".$zhuxiaomemberNum." 】  ";

        //充值总金额
        $fhmemberArr = Db::table('z_tuiguang_monitoring_xiaomi')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->join("fa_recharge_stamp_order d",'a.member_id = d.member_id','LEFT')
            ->where('d.id is not null')
            ->where($whehe)
            ->where($whehetime)
            ->group('d.member_id')
            ->column('a.member_id');

        $czallmoney = 0;
        $czrsmoney = 0;
        if(!empty($fhmemberArr)){
            $fhmemberStr = implode(',',$fhmemberArr);
            $czallmoney = Db::table('fa_recharge_stamp_order')->where("`member_id` in ($fhmemberStr)")->where($whehetimecz)->sum('pay_money');
            $czrsmoney = Db::table('fa_recharge_stamp_order')->where("`member_id` in ($fhmemberStr)")->where($whehetimecz)->group('member_id')->count('id');
        }
        $word .= "【充值总金额 ".$czallmoney."元】  【充值人数 ".$czrsmoney."人】";

        //领取视频体验卷人数
        $lqtyjmemberNum = Db::table('z_tuiguang_monitoring_xiaomi')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->join("fa_member_sftyj_log d",'a.member_id = d.member_id','LEFT')
            ->where('d.id is not null')
            ->where($whehe)
            ->where($whehetime)
            ->group('d.member_id')
            ->count('d.member_id');
        //使用视频体验卷
        $sytyjmemberNum = Db::table('z_tuiguang_monitoring_xiaomi')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
            ->join("fa_finance d",'a.member_id = d.member_id','LEFT')
            ->where('d.type = 35 and d.id is not null')
            ->where($whehe)
            ->where($whehetime)
            ->group('d.member_id')
            ->count('d.id');

        $word .= "【领取过体验卷 ".$lqtyjmemberNum."人】  【使用过体验卷 ".$sytyjmemberNum."人】";

//        //充值总金额
//        $czallmoney = Db::table('z_tuiguang_monitoring_xiaomi')
//            ->alias('a')
//            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
//            ->join("fa_task_watch_member c",'a.member_id = c.member_id','LEFT')
//            ->where($whehe)
//            ->where($whehetime)
//            ->field('(select sum(cz.pay_money) from fa_recharge_stamp_order cz where cz.member_id in (a.member_id)) as cz_money')
//            ->find();
//        var_dump($czallmoney);die;
//        $word .= "【充值总金额 ".$czallmoney." 】  ";

        $lcl_word = '';
        if (isset($param['lcl']) && !empty($param['lcl'])) {
            $lcl_word = $this->getXiaomilcl($param['lcl']);
        }

        $tjword = $this->allTjInfos('z_tuiguang_monitoring_xiaomi','小米');

        //关键词，排序等赋值
        $this->assign($request->get());
        $this->assign([
            'data'  => $data,
            'page'  => $data->render(),
            'total' => $data->total(),
            'word' => $word,
            'lcl_word' => $lcl_word,
            'tjword' => $tjword,
        ]);
        return $this->fetch();
    }


    /**
     * 查询快手单日留存率
     * User:@hang
     */
    public function getKslcl($day_time)
    {
        if(empty($day_time)){
            return 500;
        }
        $day_time_arr = explode('-',$day_time);
        if(count($day_time_arr) != 3){
            return 500;
        }
        $start_time = strtotime($day_time);
        $end_time = $start_time + 86399;

        $last_start_time = $start_time - 86400;
        $last_end_time = $end_time - 86400;
//        var_dump($start_time);
//        var_dump($end_time);
//        var_dump($last_start_time);
//        var_dump($last_end_time);
        //前一天通过快手进来的人
        $last_add_data = Db::table('z_tuiguang_monitoring_ks')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->where("b.me_add_time >= $last_start_time and b.me_add_time <= $last_end_time")
            ->field('a.member_id')
            ->select();
        //今日又玩了软件的人
        $day_wan_data = Db::table('z_tuiguang_monitoring_ks')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_stay_software c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_add_time >= $last_start_time and b.me_add_time <= $last_end_time and c.time = $start_time")
            ->field('a.member_id')
            ->select();

        $last_add_data_num = count($last_add_data);
        $day_wan_data_num = count($day_wan_data);

        $word = '';
        $word .= '【'.date('Y年m月d日',$last_start_time).' 通过快手渠道注册进入'.$last_add_data_num.'人，';
        $word .= '这些人里 '.date('Y年m月d日',$start_time).' 继续玩软件的有 '.$day_wan_data_num.'人，';
        $lcl = 0;
        if(!empty($last_add_data_num)){
            $lcl = delete0(bcmul(bcdiv($day_wan_data_num,$last_add_data_num,4),100,4));
        }
        $word .= '所以 '.date('Y年m月d日',$start_time).' 的留存率为：'.$lcl.' %】';
        return $word;
    }

    /**
     * 查询抖音单日留存率
     * User:@hang
     */
    public function getDylcl($day_time)
    {
        if(empty($day_time)){
            return 500;
        }
        $day_time_arr = explode('-',$day_time);
        if(count($day_time_arr) != 3){
            return 500;
        }
        $start_time = strtotime($day_time);
        $end_time = $start_time + 86399;

        $last_start_time = $start_time - 86400;
        $last_end_time = $end_time - 86400;
//        var_dump($start_time);
//        var_dump($end_time);
//        var_dump($last_start_time);
//        var_dump($last_end_time);
        //前一天通过抖音进来的人
        $last_add_data = Db::table('z_tuiguang_monitoring_dy')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->where("b.me_add_time >= $last_start_time and b.me_add_time <= $last_end_time")
            ->field('a.member_id')
            ->select();
        //今日又玩了软件的人
        $day_wan_data = Db::table('z_tuiguang_monitoring_dy')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_stay_software c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_add_time >= $last_start_time and b.me_add_time <= $last_end_time and c.time = $start_time")
            ->field('a.member_id')
            ->select();

        $last_add_data_num = count($last_add_data);
        $day_wan_data_num = count($day_wan_data);

        $word = '';
        $word .= '【'.date('Y年m月d日',$last_start_time).' 通过抖音渠道注册进入'.$last_add_data_num.'人，';
        $word .= '这些人里 '.date('Y年m月d日',$start_time).' 继续玩软件的有 '.$day_wan_data_num.'人，';
        $lcl = 0;
        if(!empty($last_add_data_num)){
            $lcl = delete0(bcmul(bcdiv($day_wan_data_num,$last_add_data_num,4),100,4));
        }
        $word .= '所以 '.date('Y年m月d日',$start_time).' 的留存率为：'.$lcl.' %】';
        return $word;
    }


    /**
     * 查询vivo单日留存率
     * User:@hang
     */
    public function getVivolcl($day_time)
    {
        if(empty($day_time)){
            return 500;
        }
        $day_time_arr = explode('-',$day_time);
        if(count($day_time_arr) != 3){
            return 500;
        }
        $start_time = strtotime($day_time);
        $end_time = $start_time + 86399;

        $last_start_time = $start_time - 86400;
        $last_end_time = $end_time - 86400;
//        var_dump($start_time);
//        var_dump($end_time);
//        var_dump($last_start_time);
//        var_dump($last_end_time);
        //前一天通过vivo进来的人
        $last_add_data = Db::table('z_tuiguang_monitoring_vivo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->where("b.me_add_time >= $last_start_time and b.me_add_time <= $last_end_time")
            ->field('a.member_id')
            ->select();
        //今日又玩了软件的人
        $day_wan_data = Db::table('z_tuiguang_monitoring_vivo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_stay_software c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_add_time >= $last_start_time and b.me_add_time <= $last_end_time and c.time = $start_time")
            ->field('a.member_id')
            ->select();

        $last_add_data_num = count($last_add_data);
        $day_wan_data_num = count($day_wan_data);

        $word = '';
        $word .= '【'.date('Y年m月d日',$last_start_time).' 通过vivo渠道注册进入'.$last_add_data_num.'人，';
        $word .= '这些人里 '.date('Y年m月d日',$start_time).' 继续玩软件的有 '.$day_wan_data_num.'人，';
        $lcl = 0;
        if(!empty($last_add_data_num)){
            $lcl = delete0(bcmul(bcdiv($day_wan_data_num,$last_add_data_num,4),100,4));
        }
        $word .= '所以 '.date('Y年m月d日',$start_time).' 的留存率为：'.$lcl.' %】';
        return $word;
    }


    /**
     * 查询oppo单日留存率
     * User:@hang
     */
    public function getOppolcl($day_time)
    {
        if(empty($day_time)){
            return 500;
        }
        $day_time_arr = explode('-',$day_time);
        if(count($day_time_arr) != 3){
            return 500;
        }
        $start_time = strtotime($day_time);
        $end_time = $start_time + 86399;

        $last_start_time = $start_time - 86400;
        $last_end_time = $end_time - 86400;
//        var_dump($start_time);
//        var_dump($end_time);
//        var_dump($last_start_time);
//        var_dump($last_end_time);
        //前一天通过oppo进来的人
        $last_add_data = Db::table('z_tuiguang_monitoring_oppo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->where("b.me_add_time >= $last_start_time and b.me_add_time <= $last_end_time")
            ->field('a.member_id')
            ->select();
        //今日又玩了软件的人
        $day_wan_data = Db::table('z_tuiguang_monitoring_oppo')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_stay_software c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_add_time >= $last_start_time and b.me_add_time <= $last_end_time and c.time = $start_time")
            ->field('a.member_id')
            ->select();

        $last_add_data_num = count($last_add_data);
        $day_wan_data_num = count($day_wan_data);

        $word = '';
        $word .= '【'.date('Y年m月d日',$last_start_time).' 通过oppo渠道注册进入'.$last_add_data_num.'人，';
        $word .= '这些人里 '.date('Y年m月d日',$start_time).' 继续玩软件的有 '.$day_wan_data_num.'人，';
        $lcl = 0;
        if(!empty($last_add_data_num)){
            $lcl = delete0(bcmul(bcdiv($day_wan_data_num,$last_add_data_num,4),100,4));
        }
        $word .= '所以 '.date('Y年m月d日',$start_time).' 的留存率为：'.$lcl.' %】';
        return $word;
    }


    /**
     * 查询小米单日留存率
     * User:@hang
     */
    public function getXiaomilcl($day_time)
    {
        if(empty($day_time)){
            return 500;
        }
        $day_time_arr = explode('-',$day_time);
        if(count($day_time_arr) != 3){
            return 500;
        }
        $start_time = strtotime($day_time);
        $end_time = $start_time + 86399;

        $last_start_time = $start_time - 86400;
        $last_end_time = $end_time - 86400;
//        var_dump($start_time);
//        var_dump($end_time);
//        var_dump($last_start_time);
//        var_dump($last_end_time);
        //前一天通过小米进来的人
        $last_add_data = Db::table('z_tuiguang_monitoring_xiaomi')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->where("b.me_add_time >= $last_start_time and b.me_add_time <= $last_end_time")
            ->field('a.member_id')
            ->select();
        //今日又玩了软件的人
        $day_wan_data = Db::table('z_tuiguang_monitoring_xiaomi')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_stay_software c",'a.member_id = c.member_id','LEFT')
            ->where("b.me_add_time >= $last_start_time and b.me_add_time <= $last_end_time and c.time = $start_time")
            ->field('a.member_id')
            ->select();

        $last_add_data_num = count($last_add_data);
        $day_wan_data_num = count($day_wan_data);

        $word = '';
        $word .= '【'.date('Y年m月d日',$last_start_time).' 通过小米渠道注册进入'.$last_add_data_num.'人，';
        $word .= '这些人里 '.date('Y年m月d日',$start_time).' 继续玩软件的有 '.$day_wan_data_num.'人，';
        $lcl = 0;
        if(!empty($last_add_data_num)){
            $lcl = delete0(bcmul(bcdiv($day_wan_data_num,$last_add_data_num,4),100,4));
        }
        $word .= '所以 '.date('Y年m月d日',$start_time).' 的留存率为：'.$lcl.' %】';
        return $word;
    }


    /**
     * 新增统计（和搜索无关）
     * User:@hang
     */
    public function allTjInfos($table_name,$qd)
    {
        return '';
        $start_time = strtotime(date('Y-m-d').'00:00:00');//当日开始时间
        $end_time = $start_time + 86399;//当日结束时间
//        $start_time = 1741363200;//当日开始时间
//        $end_time = 1741370400;//当日结束时间
        $start_time_hm = $start_time * 1000;//毫秒
        $end_time_hm = $end_time * 1000;//毫秒

        $infos = '';
        //平台在线男女数
        $ptboyzx = Db::table('fa_member')->where("me_zx = 0 and me_sex = 1")->count('member_id');
        $ptgirlzx = Db::table('fa_member')->where("me_zx = 0 and me_sex = 2")->count('member_id');
        $infos .= "【平台在线男女数：男 {$ptboyzx} 女 {$ptgirlzx} 】";
        //当日注册用户
        $drzcyh = Db::table('fa_member')->where("me_qd = '{$qd}' and me_add_time >= $start_time and me_add_time <= $end_time")->count('member_id');
        $infos .= "【当日注册用户：{$drzcyh} 人】";
        //当日注册男
        $drzcboyyh = Db::table('fa_member')->where("me_qd = '{$qd}' and me_sex = 1 and me_add_time >= $start_time and me_add_time <= $end_time")->count('member_id');
        $infos .= "【当日注册男：{$drzcboyyh} 人】";
        //当日充值金额
        $drczje = Db::table('fa_member')
            ->alias('a')
            ->join('fa_recharge_stamp_order b', 'a.member_id = b.member_id')
            ->where("a.me_qd = '{$qd}' and a.me_add_time >= $start_time and a.me_add_time <= $end_time and b.add_time >= $start_time and b.add_time <= $end_time")
            ->sum('b.pay_money');
        $infos .= "【当日充值金额：{$drczje} 元】";
        //当日充值人数
        $drczrs = Db::table('fa_member')
            ->alias('a')
            ->join('fa_recharge_stamp_order b', 'a.member_id = b.member_id')
            ->where("a.me_qd = '{$qd}' and a.me_add_time >= $start_time and a.me_add_time <= $end_time and b.add_time >= $start_time and b.add_time <= $end_time")
            ->group('b.member_id')
            ->count('a.member_id');
        $infos .= "【当日充值人数：{$drczrs} 人】";
        //日活跃男
        $rhyboy = Db::table('fa_member')
            ->where("me_qd = '{$qd}' and me_sex = 1")  // 筛选渠道为抖音的男用户
            ->whereBetween('me_add_time', [$start_time, $end_time])  // 用户注册时间为当天
            ->whereExists(function ($query) use ($start_time_hm,$end_time_hm) {
                $query->table('fa_rong_msg')
                    ->whereColumn('fa_rong_msg.fromUserId', 'fa_member.member_id')  // 关联用户
                    ->whereBetween('timestamp', [$start_time_hm, $end_time_hm])  // 消息发送时间为当天
                    ->group('fromUserId, toUserId')
                    ->having('COUNT(*) >= 2');
            })
            ->count();
        $infos .= "【日活跃男：{$rhyboy} 人】";
        //日活跃女
        $rhygirl = Db::table('fa_member')
            ->where("me_qd = '{$qd}' and me_sex = 2")  // 筛选渠道为抖音的男用户
            ->whereBetween('me_add_time', [$start_time, $end_time])  // 用户注册时间为当天
            ->whereExists(function ($query) use ($start_time_hm,$end_time_hm) {
                $query->table('fa_rong_msg')
                    ->whereColumn('fa_rong_msg.fromUserId', 'fa_member.member_id')  // 关联用户
                    ->whereBetween('timestamp', [$start_time_hm, $end_time_hm])  // 消息发送时间为当天
                    ->group('fromUserId, toUserId')
                    ->having('COUNT(*) >= 2');
            })
            ->count();
        $infos .= "【日活跃女：{$rhygirl} 人】";

        $start_time_old = $start_time - 86400 * 3;//三天前
        $end_time_old = $end_time - 86400 * 3;//三天前
        //老用户充值金额
        $lyhczje = Db::table('fa_member')
            ->alias('a')
            ->join('fa_recharge_stamp_order b', 'a.member_id = b.member_id')
            ->where("a.me_qd = '{$qd}' and a.me_add_time >= $start_time_old and a.me_add_time <= $end_time_old and b.add_time >= $start_time and b.add_time <= $end_time")
            ->sum('b.pay_money');
        $infos .= "【老用户充值金额：{$lyhczje} 元】";
        //老用户充值人数
        $lyhczrs = Db::table('fa_member')
            ->alias('a')
            ->join('fa_recharge_stamp_order b', 'a.member_id = b.member_id')
            ->where("a.me_qd = '{$qd}' and a.me_add_time >= $start_time_old and a.me_add_time <= $end_time_old and b.add_time >= $start_time and b.add_time <= $end_time")
            ->group('b.member_id')
            ->count('a.member_id');
        $infos .= "【老用户充值人数：{$lyhczrs} 人】";

        return $infos;
    }

}
